home *** CD-ROM | disk | FTP | other *** search
/ IRIX Patches 1995 March / SGI IRIX Patches 1995 Mar.iso / 5.3_patches / patchSG0000159 / patchSG0000159.idb / usr / include / sys / scsi.h.z / scsi.h
Encoding:
C/C++ Source or Header  |  1995-03-10  |  16.9 KB  |  445 lines

  1. #ifndef _NSCSI_
  2. #define _NSCSI_
  3. #ident    "$Revision: 3.52 $"
  4. /*
  5.  * Calls from high level driver to low level driver
  6.  *
  7.  * The following declares arrays of function pointers.  Index into them
  8.  *    with the driver number of the low level driver.  The driver number
  9.  *    can be found out with SCSI_DRIVER_NUMBER (below).  Only scsi_command()
  10.  *    may be called from interrupt.  The others should in general only be
  11.  *    called from device open and close routines.
  12.  *
  13.  * Example call:
  14.  *    (*scsi_command[scsi_driver_number(dev)])(scsi_request)
  15.  *
  16.  * scsi_command() issues a SCSI command to the low level SCSI driver.
  17.  *
  18.  *    If a contingent allegiance condition is entered (check condition
  19.  *    command status), a request sense will be automatically performed.
  20.  *    If the sr_sense field of the request is not null, the sense data
  21.  *    will be copied to the sr_sense address, but not more than
  22.  *    sr_senselen bytes.
  23.  *
  24.  *    In addition, whenever there is a contingent allegiance or SCSI bus
  25.  *    reset, all commands queued in the driver and on the device (except
  26.  *    for the command causing or noticing the error) will be returned
  27.  *    with the sr_status field set to SC_ATTN.  New commands will continue
  28.  *    to be returned with this status until the flag bit SRF_AEN_ACK is
  29.  *    set in sr_flags.
  30.  *
  31.  *    Before any command queueing is done, the device driver should do
  32.  *    a mode sense on mode page 0xA (control mode page) to discover the
  33.  *    QErr bit setting.  Error handling will not work correctly in a
  34.  *    queued environment unless the QErr bit is set.
  35.  *
  36.  * scsi_alloc() initializes a connection between a device level driver and
  37.  *    a host adaptor driver for a given controller, target, and lun.  It
  38.  *    will cause the low level driver to initialize structures needed for
  39.  *    communication if it has not already done so.
  40.  *
  41.  *    The opt argument gives additional information about how the driver
  42.  *    would like to talk to the device.  Currently, three options are
  43.  *    allowed.
  44.  *    SCSIALLOC_EXCLUSIVE causes the device to be allocated
  45.  *    exclusively for the use of the calling driver.  If a device is
  46.  *    allocated for exclusive use, no other driver may access it. Also,
  47.  *    if a device is already in use by another driver, exclusive or not,
  48.  *    an exclusive alloc will fail.
  49.  *    SCSIALLOC_NOSYNC will prevent future synchronous negotiations from
  50.  *    being attempted on this device (where possible; not all adapters
  51.  *    support this capability); only applies when no other driver already
  52.  *    has the device open.  Also see the SRF_NEG_SYNC flag below.
  53.  *    SCSIALLOC_QDEPTH is a mask for an eight bit value
  54.  *    specifying how many commands a device driver would like to
  55.  *    queue (that is, the low bits of opt are used to pass the max
  56.  *    depth the upper layer driver will use).  It is to be
  57.  *    considered advice only; the depth used may be less, but will
  58.  *    never be greater.
  59.  *
  60.  *    The cb argument is used as a callback if a request sense was done
  61.  *    as a result of a check condition from a command.  If the cb
  62.  *    argument is NULL, no callbacks will be done.  Note that having
  63.  *    a callback set may result in a driver seeing the error twice.
  64.  *    The purpose of the callback is to give make sure that a given
  65.  *    driver gets all sense data from a device, even if it is returned
  66.  *    with a command issued by a different driver.  Only one driver is
  67.  *    allowed to have a callback.  scsi_alloc() will fail if a callback
  68.  *    is requested, and another driver currently has a callback
  69.  *    registered.
  70.  *
  71.  *    A return value of SCSIALLOCOK indicates success; any other value
  72.  *    indicates an error.  0 indicates a generic error such as bad
  73.  *    values for the adapter or target; values > 1 typically are an
  74.  *    errno value from errno.h, indicating the cause of the error
  75.  *    (such as EBUSY if SCSIALLOC_EXCLUSIVE is used, and the device
  76.  *    is already allocated), or EINVAL, if a non-null callback is
  77.  *    passed, but a callback is already registered for the device.
  78.  *    Note that this is a change introduced in IRIX 5.1.1; previously
  79.  *    any non-0 return value was success.  The change was made to 
  80.  *    allow the upper level drivers to better handle errors.
  81.  *
  82.  * scsi_free() terminates a connection between a device level driver and
  83.  *    the host adaptor driver.  The host adaptor driver will free any
  84.  *    structures that it does not need.
  85.  *
  86.  *    The callback argument should be the same as that given to
  87.  *    scsi_alloc().  If it does not match, the callback will not be
  88.  *    freed up.
  89.  *
  90.  * scsi_info() issues an inquiry to the given controller, target, and lun,
  91.  *    returning a pointer to the scsi_target_info structure.  It should
  92.  *    be used to see if the device is appropriate to the driver making
  93.  *    the call.
  94.  *
  95.  *    The si_maxq field in the scsi_target_info structure (returned by
  96.  *    scsi_info()) will give queueing information.
  97.  *
  98.  * scsi_abort() aborts the request passed as an argument.  If it is
  99.  *    currently active, an abort message will be sent to the device.
  100.  *    A non-zero return indicates that the abort was successful.  Not
  101.  *    all host adaptors support this function.
  102.  *
  103.  * scsi_reset() issues a bus reset to the controller number requested.
  104.  *    A non-zero return indicates a successful reset.  Not all host
  105.  *    adaptors support this reset function.
  106.  *
  107.  * scsi_driver_table is an array indexed by adaptor (or bus) number.
  108.  *    It returns the adaptor type (a constant defined by the
  109.  *    SCSIDRIVER_XXXX #define's below.  The SCSI_XXXSTART #defines
  110.  *    define the starting adaptor number for the various controller
  111.  *    types.  The SCSI_XXXCOUNT are the number of adaptors (or buses)
  112.  *    for a given controller type.  Both SCSIDRIVER_WD93 and
  113.  *    SCSIDRIVER_WD95 are part of SGI-built SCSI controllers, and so
  114.  *    use the SCSI_SGISTART and SCSI_SGICOUNT #define's.  To give an
  115.  *    example of how this works, on an Everest, the second bus on
  116.  *    jaguar controller 4 would be considered adaptor number 137.
  117.  *    SCSI_JAGSTART is 128 + (controller 4 * 2 buses per controller) +
  118.  *    bus 1 (or the second bus on the controller) is adaptor (or bus)
  119.  *    #137 from the point of view of a SCSI device driver.
  120.  */
  121. struct scsi_request;
  122. extern void (*scsi_command[])(struct scsi_request *req);
  123. extern int (*scsi_alloc[])(u_char c, u_char t, u_char l, int opt, void (*cb)());
  124. extern void (*scsi_free[])(u_char c, u_char t, u_char l, void (*cb)());
  125. extern struct scsi_target_info * (*scsi_info[])(u_char c, u_char t, u_char l);
  126.  
  127. extern int (*scsi_abort[])(struct scsi_request *req);
  128. extern int (*scsi_reset[])(u_char c);
  129. extern int (*scsi_dump[])(u_char c);
  130.  
  131. extern u_char scsi_driver_table[];
  132.  
  133. extern char   *scsi_adaperrs_tab[];
  134.  
  135. #define SCSIALLOC_NOSYNC    0x200
  136. #define SCSIALLOC_EXCLUSIVE    0x100
  137. #define SCSIALLOC_QDEPTH    0x0FF
  138.  
  139. #define SCSIALLOCOK 1    /* succesful return value from scsi_alloc function */
  140.  
  141. /*
  142.  * To find out the driver number of a device, index into scsi_driver_table
  143.  * with the adaptor number.
  144.  */
  145. #define SCSI_TYPE_COUNT    5
  146. #define SCSIDRIVER_NULL    0
  147. #define SCSIDRIVER_WD93    1
  148. #define SCSIDRIVER_JAG    2
  149. #define SCSIDRIVER_WD95    3
  150. #define SCSIDRIVER_SCIP 4
  151.  
  152. /*
  153.  * Defines for number of SCSI buses
  154.  */
  155. #define SCSI_MAXLUN      8
  156. #if defined(EVEREST)
  157. #define SCSI_SGISTART      0
  158. #define SCSI_SGICOUNT    128
  159. #define SCSI_JAGSTART    128
  160. #define SCSI_JAGCOUNT     16
  161. #define SCSI_MAXCTLR    144
  162. #define SCSI_MAXTARG     16
  163. #else
  164.  
  165. #if defined(IP5) || defined(IP17)
  166. #define SCSI_SGISTART      0
  167. #define SCSI_SGICOUNT      4
  168. #define SCSI_JAGSTART      4
  169. #define SCSI_JAGCOUNT     16
  170. #define SCSI_MAXCTLR     20
  171. #define SCSI_MAXTARG      8
  172. #else
  173.  
  174. #if defined(IP22)
  175. #define SCSI_SGISTART      0
  176. #define SCSI_SGICOUNT      6    /* up to 2 on system board plus up to 2 GIO32bis
  177.                    (on Indy), plus up to 2 wd95 on chal S */
  178. #define SCSI_MAXCTLR      6
  179. #define SCSI_MAXTARG     16    /* wide on Indigo2, narrow for Indy */
  180. #else
  181.  
  182. #if defined(IP12) || defined(IP20)
  183. #define SCSI_SGISTART      0
  184. #define SCSI_SGICOUNT      3    /* 1 on cpu board, plus up to 2 GIO */
  185. #define SCSI_MAXCTLR      3
  186. #define SCSI_MAXTARG      8
  187. #else
  188.  
  189. #define SCSI_SGISTART      0
  190. #define SCSI_SGICOUNT      1
  191. #define SCSI_MAXCTLR      1
  192. #define SCSI_MAXTARG      8
  193. #endif
  194. #endif
  195. #endif
  196. #endif
  197. #define SCSI_MAXLU     8
  198.  
  199.  
  200. /*
  201.  * SCSI minor number masks and shifts
  202.  */
  203. #define SCSI_UNIT_MASK     0xF
  204. #define DKSC_UNIT_SHIFT    4
  205. #define TPSC_UNIT_SHIFT    5
  206.  
  207. #define SCSI_LUN_MASK     0x7
  208. #define TPSC_LUN_MASK     0x3
  209. #define DKSC_LUN_SHIFT    15
  210. #define TPSC_LUN_SHIFT    16
  211.  
  212. #define DKSC_CTLR_MASK    0x7F
  213. #define TPSC_CTLR_MASK    0x7F
  214. #define DS_CTLR_MASK    0x7F
  215. #define DKSC_CTLR_SHIFT    8
  216. #define TPSC_CTLR_SHIFT    9
  217. #define DS_CTLR_SHIFT      7
  218.  
  219. #define DKSC_UNIT(dev) ((dev >> DKSC_UNIT_SHIFT) & SCSI_UNIT_MASK)
  220. #define TPSC_UNIT(dev) ((dev >> TPSC_UNIT_SHIFT) & SCSI_UNIT_MASK)
  221.  
  222. #define DKSC_LUN(dev) ((dev >> DKSC_LUN_SHIFT) & SCSI_LUN_MASK)
  223. #define TPSC_LUN(dev) ((dev >> TPSC_LUN_SHIFT) & TPSC_LUN_MASK)
  224.  
  225. #define DKSC_CTLR(dev) ((dev >> DKSC_CTLR_SHIFT) & DKSC_CTLR_MASK)
  226. #define TPSC_CTLR(dev) ((dev >> TPSC_CTLR_SHIFT) & TPSC_CTLR_MASK)
  227. #define DS_CTLR(dev)  ((dev >> DS_CTLR_SHIFT) & DS_CTLR_MASK)
  228.  
  229. /* used to convert internal ctlr number to external */
  230. #define SCSI_CTLR_SLOTSHIFT    3
  231. #define SCSI_EXT_CTLR(si) ((((si)>>SCSI_CTLR_SLOTSHIFT) * 10) + ((si) & 7))
  232. #define SCSI_INT_CTLR(se) (((se) % 10) + (((se) / 10) << SCSI_CTLR_SLOTSHIFT))
  233.  
  234. /*
  235.  * SCSI sense defines and message external declarations
  236.  */
  237. #define    SC_NUMSENSE    0x10    /* # of messages in scsi_key_msgtab */
  238. #define    SC_NUMADDSENSE    0x71     /* # of messages in scsi_addit_msgtab */
  239. extern char *scsi_key_msgtab[], *scsi_addit_msgtab[];
  240.  
  241. /* base sense error codes */
  242. #define SC_NOSENSE        0x0
  243. #define SC_ERR_RECOVERED    0x1
  244. #define SC_NOT_READY        0x2
  245. #define SC_MEDIA_ERR        0x3
  246. #define SC_HARDW_ERR        0x4
  247. #define SC_ILLEGALREQ        0x5
  248. #define SC_UNIT_ATTN        0x6
  249. #define SC_DATA_PROT        0x7
  250. #define SC_BLANKCHK        0x8
  251. #define SC_VENDUNIQ        0x9
  252. #define SC_COPY_ABORT        0xA
  253. #define SC_CMD_ABORT        0xB
  254. #define SC_EQUAL        0xC
  255. #define SC_VOL_OVERFL        0xD
  256. #define SC_MISCMP        0xE
  257.     
  258. /* some common extended sense error codes */
  259. #define SC_NO_ADD    0x0    /* no extended sense code */
  260. #define SC_NOINDEX    0x1
  261. #define SC_NOSEEKCOMP    0x2
  262. #define SC_WRITEFAULT    0x3
  263. #define SC_NOTREADY    0x4
  264. #define SC_NOTSEL    0x5
  265. #define SC_ECC        0x10
  266. #define SC_READERR    0x11
  267. #define SC_NOADDRID    0x12
  268. #define SC_NOADDRDATA    0x13
  269. #define SC_DEFECT_ERR    0x19
  270. #define SC_WRITEPROT    0x27
  271. #define SC_RESET    0x29
  272.  
  273. /* Possible status bytes returned after a scsi command */
  274. #define ST_GOOD         0
  275. #define ST_CHECK     2
  276. #define ST_COND_MET     4
  277. #define ST_BUSY         8
  278. #define ST_INT_GOOD    16
  279. #define ST_INT_COND_MET    20
  280. #define ST_RES_CONF    24
  281.  
  282. /* Size of different scsi command classes */
  283. #define SC_CLASS0_SZ     6
  284. #define SC_CLASS1_SZ    10
  285. #define SC_CLASS2_SZ    12
  286.  
  287.  
  288. /*
  289.  * SCSI host adapter independent target information structure
  290.  * This structure is used to pass information between the host adapter drivers
  291.  * and the device drivers (disk, tape, etc.).
  292.  */
  293. struct scsi_target_info
  294. {
  295.     u_char     *si_inq;    /* inquiry data */
  296.     u_char     *si_sense;    /* sense data from last request sense */
  297.     u_char      si_maxq;    /* maximum queue depth for driver */
  298.     u_char      si_qdepth;    /* max queue depth so far */
  299.     u_char      si_qlimit:1;    /* boolean "max queue depth reached"? */
  300.     uint      si_ha_status; /* SRH_* status bits, if supported */
  301. };
  302. typedef struct scsi_target_info      scsi_target_info_t;
  303.  
  304. #define SCSI_INQUIRY_LEN    64
  305. #define SCSI_SENSE_LEN        64
  306.  
  307. /*
  308.  * Definitions for scsi_target_info.si_ha_status -- host adapter status bits
  309.  * Not all host adapter drivers will set or use these bits.
  310.  */
  311. #define SRH_CANTSYNC    0x01    /* sync xfer negotiations attempted, but 
  312.     * device doesn't support sync; BADSYNC will be set if the negotation
  313.     * itself also failed */
  314. #define SRH_SYNCXFR     0x02    /* sync xfer mode in effect; async if not set;
  315.     * async mode is the default for all devscsi devices. */
  316. #define SRH_TRIEDSYNC   0x04    /* did sync negotations at some point.  If
  317.     * SRH_CANTSYNC is not also set, the device supports sync mode. */
  318. #define SRH_BADSYNC     0x08    /* device doesn't handle sync negotations
  319.     * correctly; SRH_CANTSYNC will normally be set whenever this bit
  320.     * is set */
  321. #define SRH_NOADAPSYNC  0x10    /* scsi adapter  doesn't handle sync
  322.     * negotations or system has been configured to not allow sync xfers
  323.     * on this target */
  324. #define SRH_WIDE  0x20    /* scsi adapter supports wide SCSI */
  325. #define SRH_DISC  0x40    /* scsi adapter supports disconnect and is configured
  326.     * for it */
  327. #define SRH_TAGQ  0x80    /* scsi adapter supports tagged queuing and is
  328.     * configured for it */
  329. #define SRH_MAPUSER    0x100    /* host adapter driver can map user addrs */
  330.  
  331.  
  332. /*
  333.  * SCSI request structure
  334.  * This structure is used by a SCSI device driver to make a request to a
  335.  * SCSI host adapter.
  336.  *
  337.  * Return values from the host adaptor driver are in the fields sr_status,
  338.  * sr_scsi_status, sr_sensegotten, and sr_resid.  The sr_status field
  339.  * indicates the success or failure in circumstances that are outside the
  340.  * traditional SCSI protocol (like HW errors, cable errors, DMA errors, etc.).
  341.  * The sr_scsi_status field contains the SCSI status byte.  If the command
  342.  * generated a check condition, a request sense will be attempted.  If it
  343.  * fails, the sr_status and sr_scsi_status fields will apply to the request
  344.  * sense command, and the sr_sensegotten field will be -1.  If it succeeds,
  345.  * the sr_status and sr_scsi_status fields will be 0, and the sr_sensegotten
  346.  * will contain the number of bytes of sense data received.  The sr_resid
  347.  * field will be the difference between the number of bytes of data expected
  348.  * (in the sr_buflen field) and the number actually transferred in executing
  349.  * the command.
  350.  */
  351. struct scsi_request
  352. {
  353.     /* values filled in by device driver */
  354.     u_char     sr_ctlr;
  355.     u_char     sr_target;
  356.     u_char     sr_lun;
  357.     u_char     sr_tag;    /* first byte of tag message */
  358.  
  359.     u_char    *sr_command;    /* scsi command */
  360.     ushort     sr_cmdlen;    /* length of scsi command */
  361.     ushort     sr_flags;    /* direction of data transfer */
  362.     ulong     sr_timeout;    /* in HZ */
  363.  
  364.     u_char    *sr_buffer;    /* location of data */
  365.     uint     sr_buflen;    /* amount of data to transfer */
  366.  
  367.     u_char    *sr_sense;    /* where to put sense data in case of CC */
  368.     ulong     sr_senselen;    /* size of buffer allocated for sense data */
  369.     void    (*sr_notify)(struct scsi_request *);
  370.                 /* callback pointer */
  371.     void    *sr_bp;        /* usually a buf_t pointer */
  372.  
  373.     /* spare pointer used by device driver */
  374.     void    *sr_dev;
  375.  
  376.     /* spare fields used by host adapter driver */
  377.     void    *sr_ha;        /* usually used for linked list of req's */
  378.     void    *sr_spare;    /* used as spare pointer, int, etc. */
  379.  
  380.     /* results filled in by host adapter driver */
  381.     uint     sr_status;     /* Status of command */
  382.     u_char     sr_scsi_status; /* SCSI status byte */
  383.     u_char     sr_ha_flags;     /* flags used by host adaptor driver */
  384.     short     sr_sensegotten; /* number of sense bytes received; -1 == err */
  385.     uint     sr_resid;     /* amount of sr_buflen not transferred */
  386. };
  387. typedef struct scsi_request      scsi_request_t;
  388.  
  389. /*
  390.  * constants for scsirequest.sr_flags
  391.  */
  392. #define SRF_DIR_IN    0x0001    /* data xfer into memory (DMA write) if set */
  393. #define SRF_FLUSH     0x0002    /* data writeback/inval required */
  394. #define SRF_MAPUSER   0x0004    /* data must be "mapuser"ed */
  395. #define SRF_MAP          0x0008    /* data must be mapped */
  396. #define SRF_MAPBP     0x0010    /* data must be "mapbp"ed */
  397. #define SRF_AEN_ACK   0x0020    /* acknowledge AEN */
  398. #define SRF_NEG_SYNC  0x0040    /* attempt to negotiate sync xfer mode on
  399.     * this command (if currently async; may be ignored by some
  400.     * adapter drivers, either always, or if the driver has previously
  401.     * failed to negotiate sync xfer mode with this target); this will
  402.     * override the SCSIALLOC_NOSYNC flag to scsi_alloc, if it was
  403.     * specified.  */
  404. #define SRF_NEG_ASYNC 0x0080    /* attempt to negotiate async xfer mode on
  405.     * this command (if currently using sync xfers). */
  406.  
  407. /*
  408.  * constants for scsirequest.sr_status; corresponding text msgs in scsi.c
  409.  */
  410. #define SC_GOOD        0    /* No error */
  411. #define SC_TIMEOUT    1    /* Timeout on scsi bus (no response to selection) */
  412. #define SC_HARDERR    2    /* Hardware or scsi device error */
  413. #define SC_PARITY    3    /* Parity error on the SCSI bus during xfer */
  414. #define SC_MEMERR    4    /* Parity/ECC error on host memory */
  415. #define SC_CMDTIME    5    /* the command timed out (did not complete) */
  416. #define SC_ALIGN    6    /* i/o address wasn't properly aligned */
  417. #define SC_ATTN        7    /* unit attention received on other command
  418.                  * or new command received after a unit attn
  419.                  * without SRF_AEN_ACK set in sr_flags. */
  420. #define SC_REQUEST    8    /* error in request; malformed, for
  421.                  * non-existent device; no alloc done,
  422.                  * sr_notify not set, etc. */
  423. /*
  424.  * constants for scsirequest.sr_tag
  425.  */
  426. #define    SC_TAG_SIMPLE    0x20    /* Simple tag message */
  427. #define    SC_TAG_HEAD    0x21    /* Head of queue tag message */
  428. #define    SC_TAG_ORDERED    0x22    /* Ordered tag message */
  429.  
  430. #if _KERNEL && !_STANDALONE
  431.  
  432. extern int    dksc_ctlr(const dev_t);
  433. extern int    dksc_unit(const dev_t);
  434. extern int    tpsc_ctlr(const dev_t);
  435. extern int    tpsc_unit(const dev_t);
  436. extern int    ds_ctlr(dev_t dev);
  437. extern void    subchaninit(u_char, u_char, u_char, scsi_request_t *, uint);
  438. extern int    cdrom_inquiry_test(char *);
  439.  
  440. #endif /* _KERNEL && !_STANDALONE */
  441.  
  442. #define NUM_ADAP_ERRS (SC_REQUEST+1)
  443.  
  444. #endif /* _NSCSI_ */
  445.